package guassianElimination;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import Jama.Matrix;

public class Readarray {

	public static List<Matrix> readFile(String fileName) {
		Scanner read = null;

		try {
			read = new Scanner(new File(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		String firstLine = read.nextLine();
		String[] firstLineToken = firstLine.split(" ");
		int size = Integer.parseInt(firstLineToken[0]);

		double[][] array = new double[size][size];
		double [][] array2= new double[size][1];
		
		String line;
		String[] lineToken;
		int row = 0;
		
		while (read.hasNextLine()) {

			line = read.nextLine();
			lineToken = line.split(" ");

			if (row == size) {
				for (int col = 0; col < size; col++) {
					array2[col][0]=Double.parseDouble(lineToken[col]);
				}
				
						
			} else {

				for (int col = 0; col < size; col++) {
					array[row][col] = Double.parseDouble(lineToken[col]);
					// System.out.print(array[row][col]+ ",");
				}

			}

			// System.out.println();
			row++;

		}
		
		Matrix A = new Matrix(array);
		Matrix B = new Matrix(array2);
		List<Matrix> list = new ArrayList<Matrix>();
		list.add(A);
		list.add(B);

		read.close();
		return list;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}

}
